﻿/*
   Author: Tomer Paz
   games.com
   2009
*/

/* Pre-Dies Actions Dialog
	This dialog will ask player to choose between several protperty related actions
*/



package monopoly.GameController.Dialogs {
	
	import fl.controls.*;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.EventDispatcher;
	import monopoly.GameController.Dialogs.IDialog;
	import monopoly.GameController.Dialogs.Templates.*;
	import monopoly.Field.Field;
	import monopoly.Player.Player;
	import monopoly.GameBoard.GameBoard;
	import monopoly.Localization.*;
	
	public class PreDiesActionsDialog extends Sprite implements IDialog
		{
		protected var _myStrings:ILocalLanguage = LocalLanguage.getInstance();
		public static const ACTION_SELL		= 0;
		protected var Action_Sell:String	= _myStrings.DlgPreDiesSellOption;
		public static const ACTION_AUCTION	= 1;
		protected var Action_Auction:String	= _myStrings.DlgPreDiesAucOption;
		public static const ACTION_MORTGAGE	= 2;
		protected var Action_Mortgage:String= _myStrings.DlgPreDiesMortOption;
		public static const ACTION_UPGRADE	= 3;
		protected var Action_Upgrade:String	= _myStrings.DlgPreDiesUpgrade;
		public static const ACTION_RETURN	= 4;
		protected var Action_Return:String	= _myStrings.DlgPreDiesReturn;
		
		protected var _chosen_action:uint;
		protected var _rbuttons:Array = new Array( );
		
		public function PreDiesActionsDialog(upgradeable:Boolean)
			{
			var rbuttons:Array = [ Action_Sell, Action_Auction, Action_Mortgage, ];
			if (upgradeable)
				rbuttons.push(Action_Upgrade);
			rbuttons.push(Action_Return);
			
			var dialog = new RadiosDialog(_myStrings.DlgPreDiesLabel, _myStrings.DlgPreDiesText, rbuttons);
			dialog.addEventListener(MouseEvent.CLICK, onCmdDialogButtonClick);
			addChild(dialog);
			}
		
			
		protected function onCmdDialogButtonClick(e:MouseEvent):void
			{
			if (e.target is Button)
				{
				var dlg:RadiosDialog = e.currentTarget as RadiosDialog;
				var optionName:String = dlg.ChosenName;
				
				/* check client has chosen something */
				
				if (BasicDialog.NO_CHOICE == dlg.ChosenOption)
					return;
				
				if (optionName == Action_Sell)
					_chosen_action = ACTION_SELL;
				else if (optionName == Action_Auction)
					_chosen_action = ACTION_AUCTION;
				else if (optionName == Action_Mortgage)
					_chosen_action = ACTION_MORTGAGE;
				else if (optionName == Action_Upgrade)
					_chosen_action = ACTION_UPGRADE;
				else if (optionName == Action_Return)
					_chosen_action = ACTION_RETURN;
				else
					_chosen_action = ACTION_RETURN;
				
				/* this command is done hence shutdown the dialog */
			
				e.currentTarget.removeEventListener(MouseEvent.CLICK, onCmdDialogButtonClick);
				e.currentTarget.remove( );
				removeChild(Sprite(e.currentTarget));
				
				/* signal game controller we are done */
				
				dispatchEvent(new Event(Event.COMPLETE));
				}
			}
		
		public function get chosenAction():uint
			{
			return this._chosen_action;
			}
		}
}